//
//  ToolsViewController.m
//  A段项目,漫画
//
//  Created by dllo on 15/4/20.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "ToolsViewController.h"
#define WIDTH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#import "UMSocial.h"
#import "AboutUSViewController.h"
//#import "UMSocialSnsService.h"

@interface ToolsViewController ()<UITableViewDataSource,UITableViewDelegate,UMSocialUIDelegate>
//@property(nonatomic, retain)UITableView *ToolsTableView;
@property(nonatomic, assign)BOOL isNight;
@property(nonatomic,retain)UIImageView *aa;
@property(nonatomic,retain)NSString *imageUrl;
@end

@implementation ToolsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    self.view.backgroundColor = [UIColor whiteColor];
    self.isNight = NO;
    [self creatToolView];
    
}


#pragma mark 视图创建
-(void)creatToolView
{
    
    
    
    UIImageView *imageBack = [[UIImageView alloc]initWithFrame:CGRectMake(0 , 0, WIDTH , HEIGHT)];
    UIImage *image = [UIImage imageNamed:@"625598d5g7414fc3260a2&690.jpeg"];
    
    imageBack.image = image;
    
//    [self.view addSubview:imageBack];
    
    
    self.toolsTableView = [[UITableView alloc]initWithFrame:CGRectMake(WIDTH - 280, 0, 280, HEIGHT) style:UITableViewStylePlain];
    
    [self.toolsTableView setBackgroundView:imageBack];
    
    [self.view addSubview:self.toolsTableView];
    self.toolsTableView.backgroundColor = [UIColor clearColor];
    
    self.toolsTableView.rowHeight = HEIGHT / 10;
    
    self.toolsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [_toolsTableView release];
    
    //代理人
    self.toolsTableView.delegate = self;
    self.toolsTableView.dataSource = self;
    
}

#pragma mark 协议两个方法实现
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 8;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row == 1) {
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
//        NSURL *url = [NSURL URLWithString:self.imageUrl];
//        [cell.LoginImageView sd_setImageWithURL:url];
        
//        [cell.LoginImageView sd_setImageWithURL:[NSURL URLWithString:self.imageUrl] placeholderImage:[UIImage imageNamed:@"iconfont-denglu"]];
//        
//
//        cell.WeiboLoginLabel.text = @"点击登录";
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }else if (indexPath.row == 2){
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        UIImage *iamge = [UIImage imageNamed:@"iconfont-search"];
        cell.LoginImageView.image = iamge;
        cell.backgroundColor = [UIColor clearColor];
        cell.ProductionLabel.text = @"作品搜索";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }else if (indexPath.row == 3){
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        UIImage *iamge = [UIImage imageNamed:@"iconfont-jilu"];
        cell.LoginImageView.image = iamge;
        cell.backgroundColor = [UIColor clearColor];
        cell.BrowseLabel.text = @"浏览记录";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }else if (indexPath.row == 4){
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        UIImage *iamge = [UIImage imageNamed:@"iconfont-qingchuyuhuancun"];
        cell.LoginImageView.image = iamge;
//        cell.LoginImageView.hidden = YES;
        cell.backgroundColor = [UIColor clearColor];
        cell.ClearCacheLabel.text = @"清除缓存";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;

    }if (indexPath.row == 5) {
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        cell.backgroundColor = [UIColor clearColor];
        if (self.isNight) {
            cell.NightLabel.text = @"日间模式";
            UIImage *iamge = [UIImage imageNamed:@"iconfont-taiyang"];
            cell.LoginImageView.image = iamge;
        }else{
            cell.NightLabel.text = @"夜间模式";
            UIImage *iamge = [UIImage imageNamed:@"iconfont-yejianmoshi"];
            cell.LoginImageView.image = iamge;
        }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }if (indexPath.row == 6) {
        static NSString *reuse = @"reuse";
        ToolsLeftCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[ToolsLeftCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
        UIImage *iamge = [UIImage imageNamed:@"iconfont-guanyu"];
        cell.LoginImageView.image = iamge;
        cell.backgroundColor = [UIColor clearColor];
        cell.AboutUsLabel.text = @"关于我们";
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        static NSString *reuse = @"reuse";
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse]autorelease];
        }
    
        cell.backgroundColor = [UIColor clearColor];
        cell.selectionStyle = UITableViewCellEditingStyleNone;
        return cell;
    }
    
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    //微博登陆
    if (indexPath.row == 1) {
        
//        UMSocialSnsPlatform *snsPlatform = [UMSocialSnsPlatformManager getSocialPlatformWithName:UMShareToSina];
//        
//        snsPlatform.loginClickHandler(self,[UMSocialControllerService defaultControllerService],YES,^(UMSocialResponseEntity *response){
//            
//            //          获取微博用户名、uid、token等
//            
//            if (response.responseCode == UMSResponseCodeSuccess) {
//                
//                UMSocialAccountEntity *snsAccount = [[UMSocialAccountManager socialAccountDictionary] valueForKey:UMShareToSina];
//                
//                NSLog(@"username is %@, uid is %@, token is %@ url is %@",snsAccount.userName,snsAccount.usid,snsAccount.accessToken,snsAccount.iconURL);
//               self.imageUrl = snsAccount.iconURL;
//                [self.toolsTableView reloadData];
//            }});
//        [[UMSocialDataService defaultDataService]requestSnsInformation:UMShareToSina completion:^(UMSocialResponseEntity *response) {
//            
//            NSLog(@"SnsInformation is %@",response.data);
//        }];
//        
//        
//        [[UMSocialDataService defaultDataService]requestSnsFriends:UMShareToSina completion:^(UMSocialResponseEntity *response) {
//            
//            NSLog(@"SnsFriends is %@",response.data);
//        }];
//        
//        [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
//            NSLog(@"response is %@",response);
//        }];

        
        
    }if (indexPath.row == 2) {
        NSLog(@"作品搜索");
        NSLog(@"作品收索");
        [[MidTools shareMidTools].delegate5 searchCartoon];
        
    }if (indexPath.row == 3) {
        NSLog(@"浏览记录");
        [[MidTools shareMidTools].delegate2 closeTool];
        [[MidTools shareMidTools].delegate9 showThrough];
    }if (indexPath.row == 4) {
        NSLog(@"清除缓存");
        [[MidTools shareMidTools].delegate2 closeTool];
        [[MidTools shareMidTools].delegate4 wipe];
    }
    
    
    if (indexPath.row == 5) {
        NSLog(@"夜间模式");
        if (self.isNight) {
            [[MidTools shareMidTools].delegate2 closeTool];
            [[MidTools shareMidTools].delegate3 modexChangeByNow:YES];
            self.isNight = NO;
            [self.toolsTableView reloadData];
        }else{
            [[MidTools shareMidTools].delegate2 closeTool];
            [[MidTools shareMidTools].delegate3 modexChangeByNow:NO];
            self.isNight = YES;
            [self.toolsTableView reloadData];
        }
    }if (indexPath.row == 6) {
        NSLog(@"关于我们");
        [[MidTools shareMidTools].delegate2 closeTool];
        [[MidTools shareMidTools].delegate1 pushWithIndex:6];
    }
        
    
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    NSLog(@"开始跳转");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
